package com.jn.exam.oss.controller;


import com.jn.exam.oss.service.OssService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author 江南大学1033190417
 * @date 2021/12/16 17:11
 */
@RestController
@RequestMapping("/examoss/fileoss")
//@CrossOrigin//解决跨域
public class OssController {

    @Autowired
    private OssService ossService;

    //上传图片的方法
    @ApiOperation("上传文件")
    @PostMapping("uploadFile")
    public String uploadOssFile(MultipartFile file) {
        //获取上传文件
        return ossService.uploadFileAvatar(file);
    }

    @ApiOperation("上传文件")
    @PostMapping("upFile")
    public String upFile(MultipartFile file){
        String url = ossService.uploadFileAvatar(file);
        return "{\"location\":\""+url+"\"}";
    }

    @ApiOperation("根据文件url删除上传文件")
    @PostMapping("deleteFileByUrl")
    public boolean deleteFile(@RequestBody String url) {
        return  ossService.deleteFile(url);
    }

    @ApiOperation("使用文件的bit流上传")
    @PostMapping("uploadFileByByte")
    public String uploadOssFile(@RequestBody byte[] bytes){
        return ossService.uploadFaceImgBytes(bytes);
    }

    @ApiOperation("根据url复制文件")
    @PostMapping("copyFileByUrl")
    public String copyFileByUrl(@RequestBody String url){
        return ossService.copyFileByUrl(url);
    }
}
